package com.dz.Incubator.service.impl;

import com.dz.Incubator.dao.QueryDao;
import com.dz.Incubator.entity.QueryEntity;
import com.dz.Incubator.service.QueryService;
import com.dz.Incubator.config.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class QueryServiceImpl implements QueryService {

	private static final Logger logger = LoggerFactory.getLogger(QueryService.class);

    @Autowired
    private QueryDao queryDao;

    @Override
    public QueryEntity insert(QueryEntity queryEntity) {
        queryDao.insert(queryEntity);
        
        return queryEntity;
    }

    @Override
    public QueryEntity update(QueryEntity queryEntity) {
        queryDao.update(queryEntity);
        
        return queryEntity;
    }

    @Override
    public Integer delete(Long id) {
        int ret = queryDao.delete(id);
        return ret;
    }
    
    @Override
    public List<QueryEntity> find(Long[] ids) {
        List<QueryEntity> datas = queryDao.find(ids);
        return datas;
    }

    @Override
    public QueryEntity get(Long id) {
        QueryEntity queryEntity = queryDao.get(id);
        return queryEntity;
    }

    @Override
    public List<QueryEntity> findAll() {
    	List<QueryEntity> datas = queryDao.findAll();
    	return datas;
    }
    
    @Override
    public Pagination  findByPagination(Pagination pagination) {
    	List<QueryEntity> datas = queryDao.findByPagination(pagination);
    	pagination.setList(datas);
    	return pagination;
    }
	
	@Override
    public List<QueryEntity> insertBatch(List<QueryEntity> list) {
        int ret = queryDao.insertBatch(list);
        return list;
    }
    
    @Override
    public List<QueryEntity> updateBatch(List<QueryEntity> list) {
        int ret = queryDao.updateBatch(list);
        return list;
    }
    
    @Override
    public List<Long> deleteBatch(Long[] ids) {
        int ret = queryDao.deleteBatch(ids);
        List<QueryEntity>  datas = queryDao.find(ids);
        List<Long> list = new ArrayList<Long>();
        for (QueryEntity data : datas) {
        	list.add(data.getId());
        }
        return list;
    }
}